package com.its.common.net.core.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;

import java.net.InetSocketAddress;

/**
 * @Author xiaxp
 * @Date 9/15/22 16:17
 * @Description 通用网络传输对象
 */
@Data
@Builder
@ToString
public class GenericNetDTO<T> {
    private Sender sender;
    private T data;

    @AllArgsConstructor
    @ToString
    @Data
    @Builder
    public static class Sender {
        public String address;
        public int port;

        public InetSocketAddress getInetSocketAddress(){
            if(null == address || "".equals(address.trim())){
                return null;
            }
            return new InetSocketAddress(address, port);
        }
    }
}
